package com.alinu.settings.service.impl;

import com.alinu.settings.domain.DicType;
import com.alinu.settings.domain.DicValue;
import com.alinu.settings.mapper.DicTypeMapper;
import com.alinu.settings.mapper.DicValueMapper;
import com.alinu.settings.service.DicService;
import com.alinu.utils.SqlSessionUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author chenzuwei
 * @date 2021/3/18
 * @description 数据字典业务实现类
 */
public class DicServiceImpl implements DicService {
    private final DicTypeMapper dicTypeMapper = SqlSessionUtil.getSqlSession().getMapper(DicTypeMapper.class);
    private final DicValueMapper dicValueMapper = SqlSessionUtil.getSqlSession().getMapper(DicValueMapper.class);


    @Override
    public Map<String, List<DicValue>> getValueByType() {
        Map<String, List<DicValue>> dicValueMap = new HashMap<>();
        List<DicType> dicTypes = dicTypeMapper.getTypeList();

        for (DicType dicType : dicTypes) {
            List<DicValue> dicValues = dicValueMapper.getValueByType(dicType.getCode());

            dicValueMap.put(dicType.getCode(), dicValues);
        }

        return dicValueMap;
    }
}
